package com.example.meterialproject.activitys.transition.demo5

import android.os.Bundle
import android.transition.TransitionInflater
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.meterialproject.R
import com.google.android.material.transition.MaterialSharedAxis
import java.util.concurrent.TimeUnit

/**
 *
 * @ClassName: TransitionDemo5ToFragment
 * @Author: android 超级兵
 * @CreateDate: 4/28/22$ 10:25 AM$
 * TODO
 */
class TransitionDemo5ToFragment : Fragment() {
    companion object {
        const val TRANSITION_NAME = "transition_name"
        const val BACKGROUND_COLOR = "background_color"
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View? {
        postponeEnterTransition(0, TimeUnit.MILLISECONDS)
        return inflater.inflate(R.layout.transition_demo_to_5, container, false)
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val parentView = view.findViewById<ViewGroup>(R.id.parentView)

        arguments?.getString(TRANSITION_NAME)?.apply {
            parentView.transitionName = this
            sharedElementEnterTransition =
                TransitionInflater.from(requireContext()).inflateTransition(R.transition.slide)
        }

        arguments?.getInt(BACKGROUND_COLOR, -1)?.apply {
            parentView.setBackgroundColor(this)
        }
    }


}